/*
 * MapParser.hpp
 *
 *  Created on: 17.11.2013
 *      Author: dima
 */

#ifndef MAPPARSER_HPP_
#define MAPPARSER_HPP_


#include "../Model/Types.hpp"

#include <vector>
#include <string>
#include <SDL/SDL.h>


namespace Tanks
{

namespace Resources
{

  class MapParser
  {
  public:

    struct MapObject
    {
      SDL_Rect m_rect;
      Tanks::Model::GameObjectType m_type;
      std::string m_imageFilename;
    };

    MapParser(int argMaxX,
              int argMaxY,
              std::string argMyDir,
              std::string argFilename);
    ~MapParser();

    /*
     * Current format: x;y;w;h;gameobjecttype;imagename
     * */
    bool Parse();

    int GetNumberOfMapObjects() const { return m_mapObjects.size(); }
    // !precondition map-object number i must exist
    MapObject * GetMapObject(int argI){ return m_mapObjects[argI]; }

  private:

    bool CheckValidity(int argX,
                       int argY,
                       int argW,
                       int argH,
                       int argType,
                       std::string argImgFilename);

    void AddMapObject(int argX,
                      int argY,
                      int argW,
                      int argH,
                      Tanks::Model::GameObjectType argType,
                      std::string argImgFilename);

    std::vector<MapObject *> m_mapObjects;

    std::string m_mapFilename;

    std::string m_myDir;

    int m_maxX, m_maxY;
  };

}

}


#endif /* MAPPARSER_HPP_ */
